<template>
  <div class="container">
      <button @click="addfun()">添加</button>
      <br/>
      <!-- {{title}}----{{wenben}} -->
        <div v-for="item,index in lyb_arr" :key="index">
            <h3>{{item.title}}</h3>
            <p>{{item.wenben}}</p>
            <span>发布时间：{{item.time}}</span>
            <button @click="delfun(index)">删除</button>
            <hr>
        </div>

        <br><br>
         <div id="emit">
        <h2>兄弟组件互相传值通信</h2>   
        
        <button @click="bus()">兄弟按钮</button>
    
        </div>
       

  </div>
</template>

<script>

import Bus from './bus'
export default {
  data() {
    return {
        lyb_arr:[],
    }
  },
  props: ['title','wenben'],
  methods:{
       bus() {
          Bus.$emit('msg', '我要传给兄弟组件们，你收到没有688')
       },
      addfun(){
           var date =this.getNowTime()
            var ly =  {
                    title:this.title,
                    wenben:this.wenben,
                    time:date,
                    };
            this.lyb_arr.unshift(ly)
         this.$emit('myson',this.lyb_arr)
      },
        getNowTime(){
            var dtime = new Date();
            var nian = dtime.getFullYear(),
            yue = dtime.getMonth()+1,
            day = dtime.getDate(),
            hours = dtime.getHours(),
            fen = dtime.getMinutes(),
            miao = dtime.getSeconds()
            return nian+"-"+yue+"-"+day+" "+hours+":"+fen+":"+miao
        },
        delfun(index){
            if( confirm('确认删除吗这条留言吗')==true){
                this.lyb_arr.splice(index,1)
            }else{
                return
            } 
        },
  },
  components: {

  }
}
</script>

<style scoped>

</style>
